/**
 * 页面调试打印
 */
function Debug(id) {
    // var obj = $(id);
    var obj = document.getElementById(id);
    /*是否自动清空打印信息*/
    this.autoClearMsg = true;
    /*是否自动隐藏*/
    this.autoHideBox = true;

    /**
     * 初始化打印容器
     */

    var init = function () {
        if (!!obj) {
            obj.style.zIndex = '9999';
            obj.style.position = 'absolute';
            obj.style.width = parseInt(document.body.clientWidth - 10) + 'px';
            obj.style.left = '10px';
            obj.style.bottom = '5px';
            obj.style.color = 'rgb(255, 255, 255)';
            //obj.style.borderBottom = '1px solid rgba(255, 255, 255, 0.5)';
            obj.style.backgroundColor = 'rgba(30, 105, 160, 0.2)';
            obj.style.display = 'none';
        };

        return this;
    };

    /**
     * 打印内容信息（默认5秒后自动隐藏）
     * @param String msg 要输出的内容信息
     */
    var debugTimerId = undefined; /*定时器ID*/
    this.showTime = 5000; /*显示时间，默认5秒*/
    /**
     * @param String msg 需要打印的消息
     * @param boolean autoHide 是否自动隐藏（默认: true）
     * @param boolean autoClear 是否自动清空信息（默认: false）
     */
    this.print = function (msg, autoHide, autoClear) {
        if (!!obj) {
            if (autoClear == undefined) this.autoClearMsg = false;
            else this.autoClearMsg = !!autoClear;
            if (!!this.autoClearMsg) this.clear();
            if (obj.style.display == 'none') {
                obj.style.display = 'block';
            };
            obj.innerHTML += '<div style="border-bottom:1px solid rgba(255, 255, 255, 0.5); padding:3px 5px;">' +
                msg + '</div>';
            if (autoHide == undefined) this.autoHideBox = true;
            if (autoHide != undefined && this.autoHideBox == !0) this.autoHideBox = !!autoHide;
            else this.autoHideBox = !!autoHide;
            if (!!this.autoHideBox) {
                if (!!debugTimerId) debugTimerId = clearTimeout(debugTimerId);
                debugTimerId = setTimeout(this.hide, this.showTime);
            };
        };

        return this;
    };

    /**
     * 清空内容信息
     */
    this.clear = function () {
        if (!!obj) obj.innerHTML = '';
        return this;
    };

    /**
     * 强制隐藏
     */
    this.hide = function () {
        if (!!obj) {
            if (!!debugTimerId) debugTimerId = clearTimeout(debugTimerId);
            obj.style.display = 'none';
        }
        return this;
    };

    /**
     * 强制显示
     */
    this.show = function () {
        if (!!obj) {
            if (!!debugTimerId) debugTimerId = clearTimeout(debugTimerId);
            obj.style.display = 'block';
        }
        return this;
    };

    /**
     * 设置自动隐藏
     */
    this.setAutoHide = function (flag) {
        this.autoHideBox = !!flag;
        if (!!this.autoHideBox) {
            if (!!debugTimerId) debugTimerId = clearTimeout(debugTimerId);
            debugTimerId = setTimeout(this.hide, this.showTime);
        };
        return this;
    };

    /**
     * 设置自动清空
     */
    this.setAutoClear = function (flag) {
        this.autoClearMsg = !!flag;
        if (!!this.autoClearMsg) this.clear();
        return this;
    };

    init();
};
